package com.parkinginfo.manager;

/*
 * Author: Deepika Gohil
 */

import java.util.ArrayList;

import com.parkinginfo.adapters.GarageListAdapter;
import com.parkinginfo.adapters.PlacesListAdapter;
import com.parkinginfo.dbhelper.Place;
import com.parkinginfo.manager.R;

import android.app.Activity;
import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.Toast;

public class ListGaragesActivity extends ListActivity {

	private GarageListAdapter adapter;
	private ParkingManagerApplication app;
	
	private double lat, lon;
	//private Button removeButton;

	Context father = this;
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.show_garage_listings);
        
     //   setUpViews();
        
      //  Intent it = getIntent();
      //  Bundle annoations = it.getBundleExtra("annotations");
        
        app = (ParkingManagerApplication)getApplication();
        
        int size = app.getParkingGarages().size();
        Toast.makeText(ListGaragesActivity.this, "garage: "+ size, Toast.LENGTH_SHORT).show();
        
        adapter = new GarageListAdapter(this, app.getParkingGarages());
    //    setListAdapter(adapter);
        
        if(getIntent().getExtras() !=null)
    	{
    		lat = (getIntent().getExtras()).getDouble("lat");
    		lon = (getIntent().getExtras()).getDouble("lon");
    
    	}
        
        Toast.makeText(ListGaragesActivity.this, "lat, lon: "+ lat + ", " + lon, Toast.LENGTH_SHORT).show();
        
        ImageButton go_map = (ImageButton) findViewById(R.id.go_mapview);
        go_map.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Toast.makeText(ListGaragesActivity.this, "You clicked go_mapview in ListGaragesActivity", Toast.LENGTH_SHORT).show();

				System.out.println("You clicked go_mapview in GoogleParkingActivity");
				Intent it = new Intent(getApplicationContext(),GoogleParkingActivity.class);
				it.putExtra("lat", lat);
				it.putExtra("lon", lon);
				father.startActivity(it);
			};
		});
    }
	
	@Override
	protected void onResume() {
		super.onResume();
		adapter.forceReload();
	}

	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) 
	{
		super.onListItemClick(l, v, position, id);
		GarageObject t = adapter.getItem(position);
	//	Double lat = t.getLattitude();
	//	Double lon = t.getLongitude();
		
		Intent intent = new Intent(ListGaragesActivity.this, GoogleParkingActivity.class);
	//	intent.putExtra("lat", lat);
	//	intent.putExtra("lon", lon);
		startActivity(intent);
	}
	
	private void setUpViews() 
	{
		/*
		aroundMeButton = (Button)findViewById(R.id.aroundme_button);
		addLocButton = (Button)findViewById(R.id.addloc_button);
		
		aroundMeButton.setOnClickListener(new View.OnClickListener() {
		      public void onClick(View v) {
		    	  Intent intent = new Intent(ListGaragesActivity.this, GoogleParkingActivity.class);
				  startActivity(intent);
		        }
		      });
		addLocButton.setOnClickListener(new View.OnClickListener() {
		      public void onClick(View v) {
		    	  Intent intent = new Intent(ListGaragesActivity.this, SimpleMapsActivity.class);
				  startActivity(intent);
		        }
		      });
*/
	}

}